<include file="header" />
<div id="content" class="content">
    <menu id="publicmenu">
        <div class="pure-menu pure-menu-open">
            <ul>
                <li>
                    <a href="{:U('w3g/Public/home')}">
                        <div class="sidebar-ico sidebar-home"></div>
                        <div>广场</div>
                    </a>
                </li>
                <li>
                    <a href="{:U('w3g/Public/login')}">
                        <div class="sidebar-ico sidebar-login"></div>
                        <div>登录</div>
                    </a>
                </li>
                <li>
                    <a href="{:U('w3g/Public/register')}">
                        <div class="sidebar-ico sidebar-register"></div>
                        <div>注册帐号</div>
                    </a>
                </li>
                <li>
                    <a href="{:U('w3g/Public/about')}">
                        <div class="sidebar-ico sidebar-about"></div>
                        <div>关于我们</div>
                    </a>
                </li>
            </ul>
        </div>
    </menu>

    <div id="forgot" class="panel pure-form pure-form-stacked ts-padding20" selected="true" data-footer="none" data-menu="publicmenu" data-onload="$.ui.squareContainer();">
        <!--div id="switch_tab" class="pure-g">
            <div class="pure-u-1-2 weibo-type-nav-item <php>if($type=='email' || $type==''){</php>active<php>}</php>">通过邮箱找回</div>
            <div class="pure-u-1-2 weibo-type-nav-item <php>if($type=='phone'){</php>active<php>}</php>">通过手机找回</div>
            <php>if($type=='email' || $type == ''){</php>
                <div class="pure-u-1-2 ani" id="weibo-type-nav-bar" style="position:absolute;bottom:0;left:0;"></div>
            <php>}else{</php>
                <div class="pure-u-1-2 ani" id="weibo-type-nav-bar" style="position:absolute;bottom:0;left:50%;"></div>
            <php>}</php>
        </div>
        <div class="tabcon tab_0" <php>if($type!='email' && $type !=''){</php>style="display:none"<php>}</php>>
            <p style="color: #555555;">
                请输入您注册时使用的邮箱，系统将给您发送一封密码重置链接的邮件，请注意查收。
            </p>
            <input id="forgot-mail" type="text" class="pure-input-1" placeholder="邮箱地址"/>
            <input id="forgot-input-submit" type="submit" value="找回密码" class="pure-input-1 pure-button pure-button-primary"  data-ignore="true" onclick="findPass()" />
        </div-->
        <div class="tabcon tab_1" <php>if($type!='phone'){</php>style="display:none"<php>}</php>>
            <p style="color: #555555;">
                请输入您注册时使用的手机，系统将给发送验证码到您的手机，请注意查收。
            </p>
            <form id="find_password_form" class="pure-form" action="" method="post">
                <fieldset class="pure-group" style="position: relative;">
                    <input id="phone" placeholder="手机号" class="pure-input-1" name="phone" autocomplete="off" type="text" value="" class="s-txt">
                    <button id="reg_msg" type="button" class="pure-button pure-button-gray" onclick="regMsg()"><span>获取验证码</span></button>
                    <input name="regCode" placeholder="验证码" type="text" class="pure-input-1" id="regCode" tel="">
                </fieldset>
                <div class="txt-info" id="reg_msg_tip" style="display:none;">验证码已发送到您的手机，30分钟内输入有效，请勿泄露。</div>
            </form>           
            <input id="forgot-input-submit" type="button" value="找回密码" class="pure-input-1 pure-button pure-button-primary"  data-ignore="true" onclick="resetPass()" />
        </div>   
    </div>
    <script type="text/javascript">
        $(function(){
            $('.tab_1').show();
            /*var tab = $('#switch_tab');
            tab.find('div.weibo-type-nav-item').each(function(index){
                $(this).click(function(){
                    $('.tabcon').hide();
                    $('.tab_'+index).show(); 
                    $('#weibo-type-nav-bar').css('left', (index * 50) + '%');
                })
            });*/
        });
        /*
        var findPass = function(){
            var email = $('#forgot-mail').val(),
                subbtn = $('#forgot-input-submit'),
                enableSubBtn = function(){
                    setTimeout(function(){
                        subbtn.attr('disabled', false);
                    },2000);
                }
            if(email == ''){
                $.ui.showMask("请输入注册邮箱", true);
                enableSubBtn();
                return;
            }
            if(!TS.r.mail(email)){
                $.ui.showMask("邮箱格式不正确", true);
                enableSubBtn();
                return;
            }
            subbtn.attr('disabled', true);
            //提交注册
             $.ajax({
                type:"POST",
                url :U('w3g/Public/doFindPassByEmail'),
                data:{"email":email},
                timeout:10000,
                dataType:"json",
                success:function(w){
                    if(w.flag == 0){
                        $.ui.showMask(w.msg, true); 
                        subbtn.attr('disabled', false);
                    }else{
                        $.ui.showMask("邮件发送成功", true);
                        subbtn.attr('disabled', true);
                    }
                },
                error:function(xhr,type){
                    $.ui.showMask("连接服务器失败，请重试:)",true);
                     subbtn.attr('disabled', false);
                }
            });
        };*/
        var lock_find = 0;
        var resetPass = function(){
           var mobile = $('#phone').val().trim();
           var regCode = $('#regCode').val().trim();
           if (mobile === '') {
                    $.ui.showMask('手机号不能为空', true);
                    return false;
            }
            if( !(/^[1][358]\d{9}$/.test(mobile)) ){
                    $.ui.showMask('请填写正确的11位手机号', true);
                    return false;
            }
            if(regCode === ''){
                 $.ui.showMask('验证码不能为空', true);
                 return false;
            }
            var url1 = U('w3g/Public/doFindPasswordByMobile');
            var url2 = U('w3g/Public/isPhoneAvailable');
            var url3 = U('w3g/Public/isRegCodeAvailable');
            if(lock_find == 1){
                return false;
            }
            lock_find = 1;
            $.ajax({
                url : url2,
                data : {'phone':mobile},
                type : 'post',
                dataType : 'json',
                timeout : 2000,
                success : function(d){
                    if(d.status == 1){
                        $.ajax({
                            url : url3,
                            data : {'phone':mobile,'regCode':regCode},
                            type : 'post',
                            dataType : 'json',
                            timeout : 2000,
                            success : function(d1){
                                if(d1.status == 1){
                                    $.ajax({
                                        url : url1,
                                        type : 'post',
                                        data : $('#find_password_form').serialize(),
                                        dataType : 'json',
                                        success : function(d2){
                                            if(d2.status == 1){
                                                window.location.href = d2.data.url;
                                            }else{
                                                lock_find = 0;
                                                $.ui.showMask(d2.info, true);
                                            }
                                        }
                                    });
                                }else{
                                    lock_find = 0;
                                    $.ui.showMask(d1.info, true);
                                }
                            },
                            error: function(xhr, type){
                                lock_find = 0;
                                $.ui.showMask("连接服务器失败,请重试", true);
                            }
                        });
                    }else{
                        lock_find = 0;
                        $.ui.showMask(d.info, true);
                    }
                },
                error: function(xhr, type){
                    lock_find = 0;
                    $.ui.showMask("连接服务器失败,请重试", true);
                }
            });
            
        };
        var timenum;
        var lock = 0;
        var timefun = '';
        //发送手机验证码
        var regMsg = function () {
                var mobile = $('#phone').val().trim();
                if (mobile === '') {
                        $.ui.showMask('手机号不能为空', true);
                        return false;
                }
                if( !(/^[1][358]\d{9}$/.test(mobile)) ){
                        $.ui.showMask('请填写正确的11位手机号', true);
                        return false;
                }
                if (lock == 1) {
                        return false;
                } else {
                        timenum = 60;
                        clearInterval(timefun);
                        lock = 1;
                }
                $.post(U('w3g/Public/sendPasswordCode'), {mobile:mobile}, function(res) {
                        if (res.status == 0) {
                                lock = 0;
                                $.ui.showMask(res.info, true);
                        } else {
                                $('#reg_msg_tip').show();
                                timefun = setInterval(timeout, 1000);
                                $.ui.showMask('短信发送成功，请耐心等待', true);
                        }
                },'json');
        };
        var timeout = function () {
                timenum -= 1;
                if (timenum < 0) {
                        clearInterval(timefun);
                        timefun = '';
                        lock = 0;
                        $('#reg_msg_tip').hide();
                        $('#reg_msg').find('span').text('获取验证码');
                        $('#reg_msg').attr('disabled', false);
                        return;
                }
                $('#reg_msg').find('span').text('('+timenum+')获取验证码');
        };
    </script>
<include file="footer_public" />